package org.easy.http.client.util.json;

import org.easy.http.client.util.ClassUtils;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Comparator;

/**
 * @Description TODO
 * @Author WuXueLi
 * @Date 18:10 2023/2/4
 * @Version 1.0
 **/
public abstract class TypeRef<T> implements Comparator<T> {

    final Type type;
    final Class<? super T> rawType;

    @SuppressWarnings("unchecked")
    protected TypeRef() {
        Type superClass = getClass().getGenericSuperclass();
        if (superClass instanceof Class<?>)
            throw new IllegalArgumentException("Internal error: TypeReference constructed without actual type information");
        type = ((ParameterizedType) superClass).getActualTypeArguments()[0];
        this.rawType = (Class<? super T>) ClassUtils.getRawType(type);
    }

    /**
     * Gets underlying {@code Type} instance.
     *
     * @return {@link Type}
     */
    public Type getType() {
        return type;
    }

    /**
     * Returns the raw (non-generic) type for this type.
     *
     * @return 原始类的类型
     */
    public Class<? super T> getRawType() {
        return rawType;
    }

    /**
     * Compares its two arguments for order.  Returns a negative integer,
     * zero, or a positive integer as the first argument is less than, equal
     * to, or greater than the second.
     */
    @Override
    public int compare(T o1, T o2) {
        return 0;
    }




}
